#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QToolBar>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
//    //实例：为菜单中的子菜单创建菜单
    QMenuBar * bar = this->menuBar();
    this->setMenuBar(bar);

    QMenu * prent = new QMenu("菜单");
    bar->addMenu(prent);
//    prent->setIcon(QIcon(":/s.png"));
// //    QMenu * child = new QMenu("子菜单");

//    bar->addMenu(prent);
// //    prent->addMenu(child);

// //    QAction * action1 = new QAction("action1");
// //    QAction * action2 = new QAction("action2");
//    QAction * action1 = new QAction("保存");
//    QAction * action2 = new QAction("打开");
//    action1->setIcon(QIcon(":/s.png"));
//    action2->setIcon(QIcon(":/w.png"));
//    prent->addAction(action1);
//    prent->addAction(action2);

    //创建一个工具栏
    QToolBar * tool = new QToolBar();
    this->addToolBar(tool);
    QAction * action1 = new QAction("文件");
    QAction * action2 = new QAction("保存");
    action1->setIcon(QIcon(":/w.png"));
    action2->setIcon(QIcon(":/s.png"));
    //把工具栏中的action加入到菜单栏
    prent->addAction(action1);
    prent->addAction(action2);

    tool->addAction(action1);
    tool->addAction(action2);

}

MainWindow::~MainWindow()
{
    delete ui;
}

